package com.sie.controller;


import com.sie.dto.LoginDto;
import com.sie.service.LoginService;
import com.sie.util.ReslUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 登录登出控制器
 */
@RestController
@CrossOrigin
@SuppressWarnings("all")
@Api(tags = "用户登录及权限")
public class LoginController {

    @Autowired
    private LoginService service;

    @ApiOperation("登录接口")
    @PostMapping("/login")
    public Map login(@RequestBody @ApiParam("loginFrom") LoginDto dto) {
        Map login = service.login(dto.getUsername(), dto.getPassword());
        return login;
    }

    @PostMapping("/out")
    @ApiOperation("退出登录")
    public Map out(HttpServletResponse response) {
        response.setHeader("token", "TIME_9999");
        return ReslUtil.success();
    }
}
